package tan.dft.quanly;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class QuanlyAdapter extends ArrayAdapter<Quanly> {
	private ArrayList<Quanly> array;
	private Context mContext;

	public QuanlyAdapter(Context context, int textViewResourceId,
			ArrayList<Quanly> objects) {
		super(context, textViewResourceId, objects);
		this.mContext = context;
		this.array = objects;

	}

	// phuong thuc goi de lay tung phan tu cua mang xay dung tung item cua
	// listview
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// mang co bao nhieu phan tu se co bay nhieu item cua listview
		// buoc1: lay layout ma tao ra item (layout thu position)
		View quanlytView = convertView;
		if (quanlytView == null) {
			quanlytView = new QuanlyLayoutItem(mContext);
		}

		// buoc2: lay doi tuong sinh vien thu position
		Quanly quanly = array.get(position);

		// buoc3: lay tung thanh phan cau tao len item
		TextView qlidmay = ((QuanlyLayoutItem) quanlytView).qlidmay;
		TextView qlidql1 = ((QuanlyLayoutItem) quanlytView).qlidql1;
		TextView qlname = ((QuanlyLayoutItem) quanlytView).qlname;
		TextView add = ((QuanlyLayoutItem) quanlytView).add;
		TextView qlage = ((QuanlyLayoutItem) quanlytView).qlage;
		TextView qlgender = ((QuanlyLayoutItem) quanlytView).qlgender;
		TextView qllat = ((QuanlyLayoutItem) quanlytView).qllat;
		TextView qllng = ((QuanlyLayoutItem) quanlytView).qllng;

		// buoc4: lay tung thuoc tinh cua student de gan cho tung thanh phan cua
		// item
		qlidmay.setText("" + quanly.getIdmay());
		qlidql1.setText("" + quanly.getIdql1());
		qlname.setText("" + quanly.getName());
		add.setText("" + quanly.getAdd());
		qlage.setText("" + quanly.getAge());
		qlgender.setText("" + quanly.getGender());
		qllat.setText("" + quanly.getLat());
		qllng.setText("" + quanly.getLng());

		return quanlytView;
	}
}
